const fetch = require('node-fetch');
const retry = require('bluebird-retry');
const ERC20 = require('./contracts/erc20');
const config = require('./config');

// async function formatRacaBalance(balance) {
//     let balanceShowValue = balance / 1e18;
//     let balanceShowValue2 = Math.floor(balanceShowValue * 1000000) / 1000000;
//     return balanceShowValue2;
// }

// async function payRaca() {
//     console.log("==================开始启动RACA充值脚本========================");
    
//     try {
//         let raca = new ERC20(config.chain, config.racaContract, config.privateKey);
//         /// 验证余额
//         let balance = await raca.balanceOf(config.address);
//         let showBalance = await formatRacaBalance(balance);
//         console.log("RACA当前余额："+showBalance);
        
//         let racaPayCount = config.racaPayCount;
//         let payAmout = racaPayCount * 250;
//         console.log("准备充值："+ payAmout + " RACA");
//         if (payAmout >  showBalance) {
//             console.log("当前RACA余额不足，退出充值");
//             return;
//         } 
//         let receiveAddress = config.metamonPayAddress;
//         let amount = "250" + "000000000000000000";
//         let wait = ms => new Promise(resolve => setTimeout(resolve, ms));
//         let successCount = 0;
//         let failedCount = 0;
//         for (let i = 0; i < racaPayCount; i++) {
//             try {
//                 let result = await raca.transfer(receiveAddress, amount);
//                 console.log("第" + (i + 1) + "个交易发送成功: " + result.blockHash);
//                 successCount ++;
//                 await wait(3000);
//             } catch (err) {
//                 console.log("第" + (i + 1) + "个交易发送失败: " + err);
//                 failedCount++;
//             }
//         }
//         balance = await raca.balanceOf(config.address);
//         showBalance = await formatRacaBalance(balance);
//         console.log("RACA充值结束，成功"+successCount+"次，失败"+failedCount+"次!");
//         console.log("RACA当前余额："+showBalance);

//     } catch (error) {
//         console.log("RACA充值失败：" + error);
//     }
// }

// payRaca();

console.log("注意：RACA官方已修改充值方式，请勿使用该充值脚本！请前往官方页面进行充值！");
console.log("注意：RACA官方已修改充值方式，请勿使用该充值脚本！请前往官方页面进行充值！");
console.log("注意：RACA官方已修改充值方式，请勿使用该充值脚本！请前往官方页面进行充值！");